using System;
using System.Windows.Forms;

using FreeFlow.Administration;

namespace FreeFlowAdministrator
{
	/// <summary>
	/// Summary description for StagesAdaptor.
	/// </summary>
	public class StagesAdaptor : Adaptor, IRefreshable
	{
    private StageCollection stages;
		internal StagesAdaptor(StageCollection stages)
		{
      this.stages = stages;
		}
  
    public override void AddChildren(TreeNode node)
    {
      foreach (Stage stage in stages)
      {
        TreeNode childNode = TreeNodeFactory.CreateTreeNode(new StageAdaptor(stage));
        node.Nodes.Add(childNode);
      }  
    }

    public override string Text
    {
      get
      {
        return "Stages (" + stages.Count + ")";
      }
    }

    public override Control GetRenderer()
    {
      StagesControl control = new StagesControl();
      control.LoadStages(stages);
      control.RefreshRequired += new EventHandler(TriggerRefreshRequired);
      return control;
    }

    public override object Object
    {
      get
      {
        return stages;
      }
    }

    #region IRefreshable Members

    public void Refresh()
    {
      stages.Refresh();
    }

    #endregion
  }
}
